//
//  NewsViewController.m
//  MyLittleBrother
//
//  Created by speeda on 17/7/31.
//  Copyright © 2017年 speeda. All rights reserved.
//

#import "CompetitionViewController.h"
#import "ChartsCell.h"
#import "PKView.h"

@interface CompetitionViewController () <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *competitionTableView;
@property (nonatomic, strong) NSMutableArray *competitionArray;

@end

@implementation CompetitionViewController

- (void)viewWillAppear:(BOOL)animated{
    
    //设置导航栏背景图片为一个空的image，这样就透明了
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    //设置导航条主体颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
}

- (void)initView {

    
    self.title = @"比武场";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.competitionTableView.dataSource = self;
    self.competitionTableView.delegate = self;
    self.competitionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.competitionTableView.estimatedRowHeight = 70;
    self.competitionTableView.rowHeight = UITableViewAutomaticDimension;
    
    UIButton *rightBtton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtton addTarget:self action:@selector(rightBttonItemAction) forControlEvents:UIControlEventTouchUpInside];
    [rightBtton setTitle:@"规则" forState:UIControlStateNormal];
    [rightBtton sizeToFit];
    UIBarButtonItem *rightBttonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtton];
    self.navigationItem.rightBarButtonItem = rightBttonItem;
}


- (void)rightBttonItemAction {

    
}


- (IBAction)pkBtnAction:(id)sender {
    
    [PKView viewFormXib];
}


#pragma mark -- UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.competitionArray.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    ChartsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"ChartsCell" owner:nil options:nil];
        cell = [nibs lastObject];
    }
    cell.oneLabel.text = self.competitionArray[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 30;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,30)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"排行榜";
    
    return label;
}





- (NSMutableArray *)competitionArray {

    if (!_competitionArray) {
        _competitionArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil];
    }
    
    return _competitionArray;
}


- (void)viewWillDisappear:(BOOL)animated{
    
    //    如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];

    [self.navigationController.navigationBar setTintColor:nil];
}


@end
